package com.wuzhipeng.heart.user.controller;


import com.wuzhipeng.heart.user.convention.result.Result;
import com.wuzhipeng.heart.user.convention.result.Results;
import com.wuzhipeng.heart.user.dao.entity.Appointments;
import com.wuzhipeng.heart.user.dto.request.*;
import com.wuzhipeng.heart.user.service.IAppointmentsService;
import com.wuzhipeng.heart.user.service.ITherapistService;
import com.wuzhipeng.heart.user.service.ITherapistdataService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.w3c.dom.stylesheets.LinkStyle;

import java.util.List;

@RequiredArgsConstructor
@Slf4j
@RestController
public class TherapistController {
    private final ITherapistService therapistService;
    private final ITherapistdataService therapistdataService;
    private final IAppointmentsService appointmentsService;
    @GetMapping("/therapist/profile")
    public Result getTherapistProfile() {
        TherapistInfoDTO therapistProfile = therapistdataService.getTherapistProfile();
        return Results.success(therapistProfile);
    }
    @PutMapping("/therapist/profile")
    public Result updateTherapistProfile(@RequestBody TherapistInfoDTO therapistInfoDTO) {
        therapistdataService.updateTherapistProfile(therapistInfoDTO);
        return Results.success("success");
    }

    /**
     * 获取所有咨询师
     * @return
     */
    @GetMapping("/therapists")
    public Result getTherapists() {
        List<TherapistsDTO> therapistsDTO = therapistdataService.getTherapists();
        return Results.success(therapistsDTO);
    }
    /**
     * 查询咨询师的空闲时间段
     * @param therapistAvailableTimeDTO
     * @return
     */
    @GetMapping("/appointments/available-time")
    public Result getAvailableTime(TherapistAvailableTimeDTO therapistAvailableTimeDTO) {
        List<String> availableTime = appointmentsService.getAvailableTime(therapistAvailableTimeDTO);
        return Results.success(availableTime);

    }

    /**
     * 添加预约
     * @param makeAppointmentsDTO
     * @return
     */
    @PostMapping("/appointments")
    public Result addAppointment(@RequestBody MakeAppointmentsDTO makeAppointmentsDTO) {
        appointmentsService.addAppointment(makeAppointmentsDTO);
        return Results.success("success");
    }

    /**
     * 获取用户的预约
     * @return
     */
    @GetMapping("/appointments/user")
    public Result getUserAppointments() {
        List<UserAppointmentsDTO> userAppointments = appointmentsService.getUserAppointments();
        return Results.success(userAppointments);
    }
    /**
     * 取消预约
     * @param id
     * @return
     */
    @PostMapping("/appointments/{id}/cancel")
    public Result cancelAppointment(@PathVariable Integer id) {
        appointmentsService.cancelAppointment(Long.valueOf(id));
        return Results.success("success");
    }

    /**
     * 获取咨询师的预约统计
     * @return
     */
    @GetMapping("/therapist/stats")
    public Result getTherapistStats() {
        StatsDTO statsDTO= appointmentsService.getTherapistStats();
        return Results.success(statsDTO);
    }

    /**
     * 获取咨询师的日程
     * @return
     */
    @GetMapping("/therapist/schedule/today")
    public Result getTherapistScheduleToday() {
        List<TodayAppointmentsDTO> todayAppointmentsDTOS=appointmentsService.getTherapistScheduleToday();
        return Results.success(todayAppointmentsDTOS);
    }

    /**
     * 获取咨询师的周日程
     * @param startDate
     * @return
     */
    @GetMapping("/therapist/schedule/weekly")
    public Result getTherapistSchedule(@RequestParam String startDate) {
        List<ScheduleDTO> scheduleDTO= appointmentsService.getTherapistSchedule(startDate);
        return Results.success(scheduleDTO,"操作成功");
    }

    /**
     * 添加咨询师的日程
     * @param scheduleDTO
     * @return
     */
    @PostMapping("/therapist/schedule")
    public Result addTherapistSchedule(@RequestBody ScheduleDTO scheduleDTO) {
        appointmentsService.addTherapistSchedule(scheduleDTO);
        return Results.success("success");
    }

    /**
     * 删除咨询师的日程
     * @return
     */
    @GetMapping("/therapist/records")
    public Result getTherapistRecords() {
        List<AppointmentRecordsDTO> therapistRecordsDTOS= appointmentsService.getTherapistRecords();
        return Results.success(therapistRecordsDTOS,"success");
    }

    /**
     * 修改密码
     * @param findPasswordDTO
     * @return
     */
    @PostMapping("/auth/retrieve-password")
    public Result retrievePassword( @RequestBody FindPasswordDTO findPasswordDTO) {
        String password= therapistService.retrievePassword(findPasswordDTO.getPhone(), findPasswordDTO.getName(), findPasswordDTO.getIsClient());
        return Results.success(password,"success");
    }
    /**
     * 取消预约
     * @param id
     * @return
     */
     @PostMapping("/api/appointments/{id}/cancel")
     public Result cancelAppointmentApi(@PathVariable Integer id) {
         appointmentsService.cancelAppointment(Long.valueOf(id));
         return Results.success("success");
     }
}
